#include <iostream>

using namespace std;

const int N = 10010;
int arr[N][N];
int n;
int memo[N][N];
int dfs(int x, int y)
{
    int sum = 0;
    if (memo[x][y])
        return memo[x][y];
    if (x > n || y > n)
        sum = 0;
    else
        sum =  max(dfs(x + 1, y), dfs(x + 1, y + 1)) + arr[x][y];
    memo[x][y] = sum;
    return sum;
}

int f[N][N];
int main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= i; j++)
        {
            cin >> arr[i][j];
        }
    }
    //int res = dfs(1, 1);
    //cout << res << endl;
    for (int i = n; i >=1; i--)
    {
        for (int j = 1; j <= i; j++)
        {
            arr[i][j] += max(arr[i + 1][j], arr[i + 1][j + 1]) ;
        }
    }
    cout << arr[1][1] << "\n";
    return 0;
}